package foo.bar.wiki.web.action.comment;

import foo.bar.wiki.web.action.BaseActionBean;
import foo.bar.wiki.web.action.page.PageActionBean;
import foo.bar.wiki.web.extension.CommentTypeConverter;
import foo.bar.wiki.services.WikiService;
import foo.bar.wiki.domain.Comment;
import foo.bar.wiki.plugins.PluginException;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.integration.spring.SpringBean;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class RemoveCommentActionBean extends BaseActionBean {

    private WikiService wikiService;

    @Validate(converter = CommentTypeConverter.class)
    private Comment comment;

    public Resolution delete() throws PluginException {
        String pageId = comment.getPage().getId();
        wikiService.removeComment(comment);
        return new RedirectResolution(PageActionBean.class, "view").addParameter("page", pageId);
    }



    @SpringBean("wikiService")
    public void setWikiService(WikiService wikiService) {
        this.wikiService = wikiService;    
    }

    public Comment getComment() {
        return comment;
    }

    public void setComment(Comment comment) {
        this.comment = comment;
    }
}
